package com.apes.scm.sal.saleOrder.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.sal.saleOrder.model.Coupons;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface CouponsRepository extends CustomRepository<Coupons, String> {

    @Query(value = "select a from Coupons a where not exists(select 1 from SaleOrderCoupons b where b.couponsId = a.id)")
    List<Coupons> findAllByNotJoin();

    @Query(value = "select a from Coupons a ,SaleOrderCoupons b where a.id = b.couponsId and b.saleOrderItemId = :saleOrderItemId")
    List<Coupons> findAllByJoin(String saleOrderItemId);

    @Query(value = "select a from Coupons a where not exists(select 1 from SaleOrderCoupons b where b.couponsId = a.id) " +
            "   and a.id in :couponsId")
    List<Coupons> findAllNotJoinAndCouponsId(List<String> couponsId);

    @Modifying
    @Query("delete from Coupons a where a.id in :couponsId")
    void deleteAllById(List<String> couponsId);
}
